<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图书管理</title>

    <!--    预览路径 ,可以直接在 IDEA 打开 。如果不导入两遍就预览不了 -->
    <link rel="icon" href="../../static/favicon.ico" type="image/x-icon">
    <!--导入网页图标 -->
    <link rel="shortcut icon" href="../../static/favicon.ico" type="image/x-icon">
    <!--导入网页图标 -->
    <script src="../../static/lib/jQuery/jquery-3.5.1.min.js"></script>
    <!--导入jQuery库 -->
    <script src="../../static/lib/layui/layui.js"></script>
    <!--导入layUI库 -->
    <script src="../../static/lib/cookie/js.cookie-2.2.1.min.js"></script>
    <!--导入cookie库 -->
    <link rel="stylesheet" href="../../static/lib/layui/css/layui.css" media="all">
    <!--导入layUI css库 -->
    <link rel="stylesheet" href="../../static/css/common.css">
    <!--导入公共的css，其中可定义整个网页的配色方案 -->

</head>

<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <!-- 页面的header -->
    <div th:replace="admin/_fragments :: admin-header" class="layui-header">
        <div class="layui-logo">图书管理系统</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a class="layui-icon layui-icon-shrink-right" href="javascript:void(0)"></a>
            </li>
            <!--菜单按钮-->

            <!-- <li class="layui-nav-item"><a href="">控制台</a></li>
            <li class="layui-nav-item"><a href="">图书管理</a></li>
            <li class="layui-nav-item"><a href="">用户</a></li>
            <li class="layui-nav-item">
                <a href="javascript:;">其它系统</a>
                <dl class="layui-nav-child">
                    <dd><a href="">邮件管理</a></dd>
                    <dd><a href="">消息管理</a></dd>
                    <dd><a href="">授权管理</a></dd>
                </dl>
            </li> -->

        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:void(0)">
                    <img src="../../static/images/ashini.ico" class="layui-nav-img">
                    啊、是你
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="/admin/login">安全退出</a></li>
        </ul>
    </div>
    <!-- 页面的menu/左边的导航栏 -->
    <div th:replace="admin/_fragments :: admin-menu" id="div_side_bg" class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item">
                    <a class="" href="javascript:void(0)">用户管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:void(0)">用户列表</a></dd>
                        <dd><a href="javascript:void(0)">权限列表</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item  layui-nav-itemed">
                    <a href="javascript:void(0)">图书管理</a>
                    <dl class="layui-nav-child">
                        <dd class="layui-this"><a href="javascript:void(0)" th:href="@{/admin/book-list}">图书列表</a></dd>
                        <dd><a href="javascript:void(0)">图书类别列表</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="" href="javascript:void(0)">借阅管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:void(0)">列表一</a></dd>
                        <dd><a href="javascript:void(0)">列表二</a></dd>
                        <dd><a href="javascript:void(0)">列表三</a></dd>
                    </dl>
                </li>
                <!--                    <li class="layui-nav-item"><a href="">云市场</a></li>-->
                <!--                    <li class="layui-nav-item"><a href="">发布商品</a></li>-->
            </ul>
        </div>
    </div>
    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="width: 100%;height:98%;padding-left: 15px;padding-top: 10px;">

            <!-- 面包屑-->
            <span class="layui-breadcrumb" lay-separator=" | ">
                <a href="/admin/index">首页</a>
                <a href="/type/admin/type-list">图书管理</a>
                <a><cite>图书类别列表</cite></a>
            </span>


            <div id="search_div" style="margin-top: 10px">
                <div class="layui-inline">
                    <input class="layui-input" name="searchBookName" placeholder="按编号或类型名搜索" id="search_by_id_or_name"
                           autocomplete="off">
                </div>
                <button class="layui-btn" id="search_by_id_or_name_btn" data-type="reload">
                    <i class="layui-icon layui-icon-search"></i>
                </button>
            </div>

            <!-- layUI渲染的表格组件 -->
            <table class="layui-hide" id="test" lay-filter="test"></table>

            <!-- 表格组件上方的按钮 -->
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="getCheckData">批量删除</button>
                    <button class="layui-btn layui-btn-sm" lay-event="add_new_type">添加新图书类别</button>
                </div>
            </script>

            <!-- 表格组件内部的操作按钮 -->
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
        </div>
    </div>

    <div th:replace="admin/_fragments :: admin-footer" class="layui-footer">
        <!-- 底部固定区域 -->
        ©2020 版权归武汉理工大学计算机1702"我都行，你们商量吧"小组所有&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span style="color:rgb(144, 145, 146)">
                技术支持：https://www.layui.com/
            </span>
    </div>
</div>


<!--导入公共的js，其中实现了菜单按钮的点击事件-->
<script src="../../static/js/common.js" th:src="@{/js/common.js}"></script>

<!-- layUI执行脚本 -->
<script>
    layui.use(['element', 'table'], function () {
        var table = layui.table;
        var element = layui.element;
        table.render({
            elem: '#test',
            url: "/type/all",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            title: '图书类别表',
            cols: [
                [{
                    type: 'checkbox',
                    fixed: 'left'
                }, {
                    field: 'typeId',
                    title: '图书类别编号',
                    width: 200
                }, {
                    field: 'typename',
                    title: '图书类别名称',
                    width: 200,
                    sort: true
                },{
                    fixed: 'right',
                    title: '操作',
                    toolbar: '#barDemo',
                    width: 140
                }]
            ],
            page: true,
            id: 'table_id'
        });


        //表格渲染重载,通过where字段传递查询条件 searchName
        var $ = layui.$, active = {
            reload: function () {
                //执行重载
                table.reload('table_id', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                        //查询条件
                        queryCondition: $('#search_by_id_or_name').val()
                        //这里可以传对象
                    }
                });
            }
        };

        //搜索框点击事件
        $('#search_div .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    //data是一个数组
                    var data = checkStatus.data;
                    //layer.alert(JSON.stringify(data))
                    if(data.length===0){
                        layer.msg("请选择要删除的图书类别");
                    }else{
                       var typenames= [];
                        data.forEach(type=>typenames.push(type.typename));
                        layer.confirm("确定要删除'"+typenames+"'这些图书类别?",function () {
                            var ids = "";
                            data.forEach(type=>ids=ids+","+type.typeId);
                            if(ids.length>=2){
                                ids = ids.substring(1);
                            }
                            window.location.href = "/type/deleteAll?ids="+ids;
                        })
                    }
                    break;
                case "add_new_type":
                    window.location.href = "/type/admin/type-input?typeId=-1";
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除"'+data.typename+'"这个图书类别吗？', function (index) {
                    window.location.href = "/type/delete?typeId="+data.typeId;
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                window.location.href = "/type/admin/type-input?typeId="+data.typeId;
            }
        });
    });
</script>


<!--author : 计算机1702  zhao fan -->
</body>

</html>